import { Exclude } from 'class-transformer'
import { Column, BaseEntity, Entity, PrimaryGeneratedColumn } from 'typeorm'

@Entity('tk_user')
export class UserEntity extends BaseEntity {
  @PrimaryGeneratedColumn({
    type: 'int',
    name: 'id',
    comment: 'id',
    unsigned: true,
  })
  id: number

  @Column('varchar', {
    name: 'username',
    nullable: true,
    comment: '登录名',
    length: 255,
  })
  username: string | null

  @Column('tinyint', {
    name: 'status',
    nullable: true,
    comment: '用户状态',
    width: 1,
  })
  status: boolean | null

  @Column('varchar', {
    name: 'avatar',
    nullable: true,
    comment: '用户头像',
    length: 100,
  })
  avatar: string | null

  @Column('varchar', {
    name: 'nickname',
    nullable: true,
    comment: '昵称',
    length: 255,
  })
  nickName: string | null

  @Column({
    comment: '密码',
    nullable: true, // 因为此属性后来才加，不设置nullable无法新增此属性
    length: 100,
  })
  @Exclude({ toPlainOnly: true })
  @Column({ select: false })
  password: string | null

  @Column('tinyint', {
    name: 'sex',
    nullable: true,
    comment: '性别',
    unsigned: true,
  })
  sex: number | null

  @Column('varchar', {
    name: 'email',
    nullable: true,
    comment: '邮箱',
    length: 50,
  })
  email: string | null

  @Column('datetime', {
    name: 'create_time',
    nullable: true,
    comment: '创建时间',
    default: () => 'CURRENT_TIMESTAMP',
  })
  createTime: Date | null

  @Column('datetime', {
    name: 'update_time',
    nullable: true,
    default: () => 'CURRENT_TIMESTAMP',
  })
  updateTime: Date | null
}
